package com.server.controller;

import com.common.context.BaseContext;
import com.common.result.Result;
import com.pojo.dto.UserInfoDTO;
import com.pojo.entity.UserInfo;
import com.pojo.vo.UserInfoBaseVO;
import com.server.service.UserInfoService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userInfo")
@Slf4j
@Api(tags = "用户信息接口")
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;
    @GetMapping
    public Result<UserInfo> getUserInfoByUserId(){

        Integer userId = BaseContext.getCurrentId();
        UserInfo userInfo = userInfoService.selectByUserId(userId);
        log.info("用户信息:{}",userInfo);
        return Result.success(userInfo);
    }
    @PutMapping
    public Result alertUserInfo(@RequestBody UserInfoDTO userInfoDTO){
        UserInfo userInfo = UserInfo.builder().userId(BaseContext.getCurrentId()).build();
        BeanUtils.copyProperties(userInfoDTO,userInfo);
        userInfoService.updateUserInfo(userInfo);
        return Result.success();
    }
    @GetMapping("/baseInfo")
    public Result<UserInfoBaseVO> getBaseUserInfo(){
        Integer userId = BaseContext.getCurrentId();
        UserInfoBaseVO userInfoBaseVO = userInfoService.selectBaseUserInfo(userId);
        return Result.success(userInfoBaseVO);
    }
    @GetMapping("/GetBaseInfoByUserId")
    public Result<UserInfoBaseVO> getBaseUserInfoByUserId(Integer userId){
        UserInfoBaseVO userInfoBaseVO = userInfoService.selectBaseUserInfo(userId);
        return Result.success(userInfoBaseVO);
    }
}
